package com.fenghongzhang.day004_rxjava_rxretrofit;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class Main2Activity extends AppCompatActivity {

    private static final String TAG = "Main2Activity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        //请求了一半+ 接口的一部分
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://49.233.0.68:8080/")
                .client(new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
                .addConverterFactory(GsonConverterFactory.create())
                .build();


        Api api = retrofit.create(Api.class);

//        Call<Food> food = api.getFood1("2");
//        Call<Food> food = api.getFood2("ios");
//        Call<Food> food = api.getFood3();

        final Call<Food> food = api.getFood();
        food.enqueue(new Callback<Food>() {
            @Override
            public void onResponse(Call<Food> call, Response<Food> response) {
                List<Food.DataBean> data = response.body().getData();
                Log.i(TAG, "onResponse: "+data.size());
                //

            }

            @Override
            public void onFailure(Call<Food> call, Throwable t) {

            }
        });
//        Call<User> bawei = api.login("1704", "bawei");
//        bawei.enqueue(new Callback<User>() {
//            @Override
//            public void onResponse(Call<User> call, Response<User> response) {
//                Log.i(TAG, "onResponse: "+response.body().getMessage());
//            }
//
//            @Override
//            public void onFailure(Call<User> call, Throwable t) {
//
//            }
//        });

    }
}
